package com.admin.education.dataTransferObject.userAnswerSheet.Mapper;

import com.admin.education.dataTransferObject.userAnswerSheet.UserAnswerSheetQuestionTransfer;
import com.admin.education.models.UserAnswerSheet;
import com.admin.education.models.UserAnswerSheetQuestion;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mapper
public abstract class UserAnswerSheetQuestionMapper {
    @Autowired
    private UserAnswerMapper userAnswerMapper;
    @Mappings({
            @Mapping(target = "answers", ignore = true),
            @Mapping(target = "yourAnswers", ignore = true),
    })
    public abstract UserAnswerSheetQuestionTransfer mapFrom(UserAnswerSheetQuestion userAnswerSheetQuestion);

    @Mappings({})

    public abstract List<UserAnswerSheetQuestionTransfer> mapFrom(List<UserAnswerSheetQuestion> userAnswerSheetQuestions);

    @AfterMapping
    public void afterMapping(UserAnswerSheetQuestion userAnswerSheetQuestion, @MappingTarget UserAnswerSheetQuestionTransfer userAnswerSheetQuestionTransfer) {
        if (null != userAnswerSheetQuestion.getUserAnswerSheetOwns()) {
            userAnswerSheetQuestionTransfer.setYourAnswers(userAnswerMapper.mapFromOwn(userAnswerSheetQuestion.getUserAnswerSheetOwns()));
        }
        if (null != userAnswerSheetQuestion.getUserAnswerSheetAnswers()) {
            userAnswerSheetQuestionTransfer.setAnswers(userAnswerMapper.mapFrom(userAnswerSheetQuestion.getUserAnswerSheetAnswers()));
        }
    }
}
